<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新增授权账号</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/page.css">
    <script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/media.js"></script>
    <script src="../js/common.js"></script>
    <style>
    	.son_img img{
    		width: 0.4rem;
    		height: 0.4rem;
    		display: block;
    	}
    	.son_info span{
    		display: block;
    		width: 50%;
    		height: 0.4rem;
    		float: left;
    		line-height: 0.4rem;
    	}
    </style>
</head>
<body>
    <!--头部-->
    <div class="public-header flex">
        <!--<span class="public-header-left-search"></span>-->
        <span class="public-header-left-back"></span>
        <span class="public-header-center">新增授权账号</span>
        <span class="public-header-right"></span>
    </div>
    <!--正文-->
    <div class="Authorized-account-management bc-gray">
        <ul>
            <li class="flex">
                <span>新增授权账号</span>
                <em></em>
            </li>
            <li class="flex" style="padding-right:0;">
                <input id="new_phone" type="tel" maxlength="11" placeholder="授权用户的电话号码">
                <button class="accredit">授权</button>
            </li>
        </ul>
        <p class="p">授权账号</p>
        <ul id="son" style="font-size:.14rem;">
            <li class="flex son_info">
                <span class="son_img">头像</span>
                <span class="son_num">账号</span>
            </li>
            <li class="son_info son_info_clone" style="display: none;">
            	<span class="son_img">
            		<img src="../img/denglu.png" />
            	</span>
                <span class="son_num">
                	
                </span>
            </li>
        </ul>
    </div>
</body>
<script type="text/javascript">
	var storeId = sessionStorage.s_id;
	$('.accredit').click(function(){
		var phone = $('#new_phone').val();
		$.ajax({
			type:"post",
			url:base_url+"ZITAOHUI/store/addStoreAuxiliary",
			async:true,
			data:{
				"userPhone":phone,
				"storeId":storeId
			},
			success:function(data){
				console.log(data);
				if(data.code==1){
					alert('绑定成功');
//					var clone = $('.son_info_clone').clone();
//					clone.find('img').attr('src',data.extend.auxiliary_user.user_image);
//					clone.find('son_num').text(data.extend.auxiliary_user.user_Phone);
//					clone.show().appendTo($("#son"));
					get_son();
				}else{
					alert("暂未发现此账号，请重试！");
				}
			},
			error:function(){
				alert('网络错误')
			}
		});
	})
	get_son();
	function get_son(){
		$.ajax({
			type:"post",
			url:base_url+"ZITAOHUI/store/findStoreAuxiliaryList",
			async:true,
			data:{
				"storeId":storeId
			},
			success:function(data){
				if(data.code==1){
					$('.son_info_clone:gt(0)').remove();
					for (var i = 0;i<data.extend.user_list.length;i++) {
						var clone = $('.son_info_clone').eq(0).clone();
						clone.find('img').attr('src',data.extend.user_list[i].user_image);
						clone.find('.son_num').text(data.extend.user_list[i].user_Phone);
						clone.show().appendTo($("#son"));
					}
				}else{
					alert(data.extend.msg);
				}
			},
			error:function(){
				alert('网络错误');
			}
		});
	}
</script>
</html>